import type { RouteRecordRaw } from 'vue-router'

export type PageDef = {
    component: () => any
}
function handlePages(): { [k: string]: RouteRecordRaw } {
    const pages: { [k: string]: RouteRecordRaw } = {}
    const modules: any = import.meta.glob('./**/*.ts', {
        eager: true
    })
    const { VITE_SERVICE_ENV = 'dev' } = import.meta.env
    for (const path in modules) {
        if (VITE_SERVICE_ENV != 'dev' && path == './builtin/demo.ts') {
            //非开发模式，要忽略demo里的配置
            continue
        }
        const items = modules[path].default
        if (typeof items == 'object') {
            Object.keys(items).forEach((key) => {
                const item = items[key]
                if (item.meta?.autoMount) {
                    //配置了自动挂载的，已经在router/routes/index.ts中处理了
                } else {
                    pages[key] = item
                }
            })
        }
    }
    return pages
}

export const Pages = handlePages()
